package com.zyt.i18n.document;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zyt.i18n.baidufanyi.TransApi;

/**
 * @version V1.0
 * @program: i18nTool
 * @description: (描述文件作用)
 * @author: zhang_yt@suixingpay.com
 * @create: 2019/01/15 10:11
 * @CopyRight 随行付支付有限公司
 **/
public class BaiduFanYi {

    // 在平台申请的APP_ID 详见 http://api.fanyi.baidu.com/api/trans/product/desktop?req=developer
    private static final String APP_ID = "20190115000256922";
    private static final String SECURITY_KEY = "PaFm8FvQh9o8cSBtobBN";

    /*public static void main(String[] args) {
        TransApi api = new TransApi(APP_ID, SECURITY_KEY);

        String query = "高度600米";
        String transResult = api.getTransResult(query, "auto", "en");
        //JSON jsonStr = JSON.parseObject(transResult);
        JSONObject jsonObject = JSON.parseObject(transResult);
        String trans_result = jsonObject.getString("trans_result");
        JSONArray jsonArray = JSON.parseArray(trans_result);
        //遍历方式2
        for (Object obj : jsonArray) {
            JSONObject transResultObj = (JSONObject) obj;
            String dst = transResultObj.getString("dst");
            System.out.print(dst);
        }

    }*/

    /**
     * 功能描述
     * @author zhang_yt@suixingfu.com
     * @date   2019/1/15
     * @param chinese
     * @param fromLanguage
     * @param toLanguage
     * @return java.lang.String
     */
    public static String chineseFanYi(String chinese,String fromLanguage,String toLanguage){
        TransApi api = new TransApi(APP_ID, SECURITY_KEY);
        String transResult = api.getTransResult(chinese, fromLanguage, toLanguage);

        JSONObject jsonObject = JSON.parseObject(transResult);
        String trans_result = jsonObject.getString("trans_result");
        JSONArray jsonArray = JSON.parseArray(trans_result);
        //遍历方式2
        for (Object obj : jsonArray) {
            JSONObject transResultObj = (JSONObject) obj;
            String dst = transResultObj.getString("dst");
            return  dst;
        }
        return null;
    }



}
